const sinon = require("sinon");
const menu = require('../lib/menu');
const scanfCheck = require('../lib/scanfCheck');
const printScore = require('../lib/printScore');

describe('menu()', () => {

    it('should display main menu once started', () => {
        sinon.spy(console, 'log');
        menu();
        expect(console.log.args.join()).toBe(`1. 添加学生\n`+
        `2. 生成成绩单\n`+
        `3. 退出\n`+
        `请输入你的选择（1～3）：`);
    });

});

describe("scanfCheck()",() => {
    it('scoreCheck(),should return score object',() => {
        let scoreArray = ["Math:43","Eng:78","Chi:98","Code:199"];
        let resultObj = scanfCheck.scoreCheck(scoreArray).toString();
        let expectObj = { Math: '43', Eng: '78', Chi: '98', Code: '199' }.toString();
        expect(expectObj).toBe(resultObj);
    });
    it('scanfStudentIdcheck()',() => {
        let result1 = scanfCheck.scanfStudentIdCheck("1000,4232,2123");
        let result2 = scanfCheck.scanfStudentIdCheck("ad,212,da");

        expect(true).toBe(result1);
        expect(false).toBe(result2);
    })
});

describe("printScore()",() => {
    it("print Score",() => {
        spyOn(console, 'log');
        let student = [{name:"zhangh",
                        id:'1234',
                        etchin:"h",
                        klass:"21",
                        score:{Math:"100",Eng:"90",Chi:"95",Code:"95"}}];
        let studentid = ['1234'];  
        printScore(student,studentid);
        expect(console.log).toHaveBeenCalledWith(`姓名|数学|语文|英语|编程|平均分|总分\n`+
        `========================\n`+
        `zhangh|100|95|90|95|95.0|380\n`+
        `========================\n`+
        `全班总分平均数：xxx\n`+
        `全班总分中位数：xxx\n`);
    })
})

